package com.dormitory.controller;

import com.dormitory.bean.DormitoryBean;
import com.dormitory.bean.NotificationBean;
import com.dormitory.httpHelper.HttpAddNotification;
import com.dormitory.httpHelper.HttpGetInfo;

import org.json.JSONException;

import java.io.IOException;
import java.util.List;

/**
 * Created by JHF on 2017/10/19.
 */

public class DormitoryController {
    private static DormitoryController _dormitoryController;
    public static DormitoryController getInstance() {
        if(_dormitoryController == null) {
            _dormitoryController = new DormitoryController();
        }
        return _dormitoryController;
    }
    public DormitoryBean getDormitory(int id) throws IOException, JSONException {
        return HttpGetInfo.getDormitory(id);
    }
    public List<NotificationBean> getNotifications(int dormitoryId) throws IOException, JSONException {
        return HttpGetInfo.getNotifications(dormitoryId);
    }
    public List<DormitoryBean> getFriendDormitory(int dormitoryId) throws IOException, JSONException {
        return HttpGetInfo.getFriendDormitory(dormitoryId);
    }
    public int addnotification(String title, String content,int dormitoryid,String ausername) {
        try {
            return HttpAddNotification.AddNotificationByGet(title, content, dormitoryid,ausername);
        } catch (Exception e) {
            e.printStackTrace();
            return 2;
        }
    }
}
